package cn.summit.serialization.utils;

import cn.summit.enums.EnumVO;
import cn.summit.serialization.service.AttUrlService;
import cn.summit.serialization.service.DictSerialService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author summit
 * @since 2020/11/17 10:49
 */
public class SeriUtils implements InitializingBean {

    private static SeriUtils instance;

    @Autowired(required = false)
    private AttUrlService attUrlService;

    @Autowired(required = false)
    private DictSerialService dictSerialService;

    private void setInstance(SeriUtils utils) {
        instance = utils;
    }

    /**
     * 获取文件url路径
     *
     * @param bizId 业务id
     * @return url & bizId
     */
    public static EnumVO getAttUrl(String bizId) {
        if (instance.attUrlService == null) {
            return null;
        }
        return instance.attUrlService.getAttUrl(bizId);
    }


    /**
     * 字典翻译
     *
     * @param parentCode 字典类别
     * @param dictCode 字典code
     * @return 字典
     */
    public static EnumVO getDict(String parentCode, String dictCode) {
        if (instance.dictSerialService == null) {
            return null;
        }
        return instance.dictSerialService.getDictTranslate(parentCode, dictCode);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        setInstance(this);
    }
}
